﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace BierdopjeTV.Import
{
    class FileSystemHelper
    {
        static List<string> m_SubFolders = new List<string>();

        public static List<string> getScanFolders(List<string> ScanFolders)
        {
            //_ScanFolders.Add(@"S:\Burn Notice");
            //_ScanFolders.Add(@"S:\Cougar Town");
            //_ScanFolders.Add(@"S:\Criminal Minds");
            //_ScanFolders.Add(@"S:\Hustle");
            //_ScanFolders.Add(@"S:\American Dad");
            //_ScanFolders.Add(@"S:\CSI Miami");

            //ScanFolders.Add(@"S:\");
            
            for (int i = 0; i < ScanFolders.Count; i++)
            {
                m_SubFolders.Add(ScanFolders[i]);
                getSubFolders(ScanFolders[i]);   
            }

            return m_SubFolders;

        }
                
        private static void getSubFolders(string Path)
        {
            string[] Folder = Directory.GetDirectories(Path);

            for (int j = 0; j < Folder.Length; j++)
            {
                Helpers.Logger.WriteSimpel(Folder[j]);

                m_SubFolders.Add(Folder[j]);
                getSubFolders(Folder[j]);
            }

        }

        public static List<string> ListFiles(string Path)
        {
            List<string> _LocalFiles = new List<string>();

            string[] Files = Directory.GetFiles(Path, "*.*", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < Files.Length; i++)
            {
                if (IsVideoFile(Files[i]))
                {
                    _LocalFiles.Add(Files[i]);
                }

            }
            return _LocalFiles;
        }

        private static bool IsVideoFile(string file)
        {
            
            if (file.EndsWith(".MKV", StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }
            else if (file.EndsWith(".WMV", StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }
            else if (file.EndsWith(".AVI", StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }

}
